package com.zhixin.fans.ks.ui.charge;

import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zhixin.fans.ks.R;
import com.zhixin.fans.ks.api.res.CoinOption;

import java.util.List;


public abstract class CoinChargeAdapter extends BaseQuickAdapter<CoinOption, BaseViewHolder> implements BaseQuickAdapter.OnItemClickListener {


    private int mPos = 0;


    public CoinChargeAdapter(@Nullable List<CoinOption> data) {
        super(R.layout.item_coin_option, data);
        setOnItemClickListener(this);
    }

    @Override
    protected void convert(BaseViewHolder helper, CoinOption item) {
        helper.itemView.setSelected(helper.getAdapterPosition() == mPos);
        if (mPos == helper.getAdapterPosition()) {
            onItemSelected(item);
        }
        helper.setText(R.id.tv_pay_desc, item.getP_title());
        helper.setText(R.id.tv_pay_money, String.format("￥%s", item.getP_money()));
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        mPos = position;
        notifyDataSetChanged();
    }


    public abstract void onItemSelected(CoinOption coinOption);

}
